<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>

<div class="content-wrap">
    <div class="wrapper" style="bottom: 50px;">
        <ul class="nav nav-tabs">
            <li>
                <a href="#"
                   onclick="loadDiv('rigthCenterDiv','${ctx}/drug/drugDict/dialog?drugCode=${drugDict.drugCode}&drugName=${drugDict.drugName}')">规格列表</a>
            </li>
            <li class="active">
                <c:choose>
                    <c:when test="${drugDict.id==''|| drugDict.id==null}">
                        <a href="#">
                            添加规格
                        </a>
                    </c:when>
                    <c:otherwise><a href="#">规格修改</a></c:otherwise>
                </c:choose>
            </li>
        </ul>
        <section class="panel panel-default">
            <div class="panel-body">
                <div class="col-lg-12">
                    <form:form id="inputForm" data-parsley-validate="" modelAttribute="drugDict"
                               onsubmit="return formSaveLoad('rigthCenterDiv','inputForm','${ctx}/drug/drugDict/save','${ctx}/drug/drugDict/dialog?drugCode=${drugDict.drugCode}&drugName=${drugDict.drugName}');"
                               method="post" class="form-horizontal">
                    <div class="form-group">
                        <div class="col-sm-4">
                            <form:hidden  path="id" id="id" htmlEscape="false" class="form-control" readonly="true"
                                        hidden="true"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">药品代码：</label>

                        <div class="col-sm-4">
                            <form:input path="drugCode" id="drugCode" htmlEscape="false" class="form-control"
                                        maxlength="20" readonly="true"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">药品名称：</label>
                        <div class="col-sm-4">
                            <form:input path="drugName" id="drugName1"
                                        htmlEscape="false" class="form-control" data-parsley-required="true"/>
                        </div>
                    </div>
                        <%--<div class="form-group">--%>
                            <%--<label class="col-sm-2 control-label">药品名称：</label>--%>

                            <%--<div class="col-sm-4">--%>
                                <%--<form:input path="drugName" id="drugName" htmlEscape="false" class="form-control"--%>
                                            <%--maxlength="100" readonly="true"/>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">最小单位剂量：</label>

                        <div class="col-sm-4">
                            <form:input path="dosePerUnit" id="dosePerUnit" onChange="changeDosePerUnit()"
                                        htmlEscape="false" class="form-control" data-parsley-required="true"
                                        data-parsley-type="number"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">剂量单位：</label>

                        <div class="col-sm-4">
                            <form:select path="doseUnits" id="doseUnits" onChange="changeDoseUnits()"
                                         class="form-control" data-parsley-required="true">
                                <form:option value="" label="" data-parsley-required="true"/>
                                <form:options items="${fns:getDictList('dose_unit')}" itemLabel="label"
                                              itemValue="value" htmlEscape="false" data-parsley-required="true"/>
                            </form:select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">规格：</label>

                        <div class="col-sm-4">
                            <form:input path="drugSpec" id="drugSpec" htmlEscape="false" class="form-control"
                                        maxlength="20" data-parsley-required="true"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">单位：</label>

                        <div class="col-sm-4">
                            <form:select path="unit" class="form-control" data-parsley-required="true">
                                <form:option value="" label="" data-parsley-required="true"/>
                                <form:options items="${fns:getDictList('SPEC_UNIT')}" itemLabel="label"
                                              itemValue="value" htmlEscape="false" data-parsley-required="true"/>
                            </form:select>
                        </div>
                    </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">药品含量：</label>

                            <div class="col-sm-4">
                                <form:input path="drugContent" id="drugContent" htmlEscape="false" class="form-control"
                                            maxlength="64" />
                            </div>
                        </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">毒理分类：</label>

                        <div class="col-sm-4">
                            <form:select path="toxiProperty" class="form-control" data-parsley-required="true">
                                <form:option value="" label=""/>
                                <form:options items="${fns:getDictList('DRUG_TOXI_PROPERTY_DICT')}" itemLabel="label"
                                              itemValue="value" htmlEscape="false" data-parsley-required="true"/>
                            </form:select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">OTC：</label>

                        <div class="col-sm-4">
                            <form:select path="isOtc" class="form-control" data-parsley-required="true">
                                <form:option value="" label=""/>
                                <form:options items="${fns:getDictList('YES_NO')}" itemLabel="label" itemValue="value"
                                              htmlEscape="false"/>
                            </form:select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">限制等级：</label>

                        <div class="col-sm-4">
                            <form:select path="limitClass" class="form-control" data-parsley-required="true">
                                <form:option value="" label=""/>
                                <form:options items="${fns:getDictList('LIMIT_CLASS_DICT')}" itemLabel="label"
                                              itemValue="value" htmlEscape="false"/>
                            </form:select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">贵重等级：</label>

                        <div class="col-sm-4">
                            <form:select path="preciousFlag" class="form-control" data-parsley-required="true">
                                <form:option value="" label=""/>
                                <form:options items="${fns:getDictList('DRUG_PRECIOUS_FLAG_DICT')}" itemLabel="label"
                                              itemValue="value" htmlEscape="false"/>
                            </form:select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存">&nbsp;
                            <input id="btnCancel" class="btn" type="button" value="返 回"
                                   onclick="loadDiv('rigthCenterDiv','${ctx}/drug/drugDict/dialog?drugCode=${drugDict.drugCode}&drugName=${drugDict.drugName}')">
                        </div>
                        </form:form>
                    </div>
                </div>
            </div>
        </section>
    </div>
</div>
</div>

<script>
    //如果标题是修改属性，那么最小单位剂量、剂量单位、规格、单位四个字段不可编辑更改
    var idValue = document.getElementById('id').value;



    if (null != idValue && idValue != '') {
        $.ajax({
            type: "POST",
            url: '${ctx}/drug/drugInfo/findByDrugId?drugDict.id='+idValue,
            'contentType': 'application/json',
            dataType: "json",
            success: function (data) {
                if (data.code == "success") {

                } else {
                    var dosePerUnitValue = document.getElementById('dosePerUnit'); //最小单位剂量
                    var doseUnitsValue = document.getElementById('doseUnits');     //剂量单位
                    var drugSpecValue = document.getElementById('drugSpec');      //规格
                    var unitValue = document.getElementById('unit');              //单位
                    dosePerUnitValue.readOnly = true;
                    doseUnitsValue.disabled = true;
                    drugSpecValue.readOnly = true;
                    unitValue.disabled = true;
                    $('#drugName1').attr("disabled","true");
                }
            }
        });

    }

    //隐藏ID列
    document.getElementById('id').style.display = 'none';

    function changeDosePerUnit() {
        var dosePerUnit = document.getElementById("dosePerUnit").value;
        var doseUnits = document.getElementById("doseUnits").value;
        $("#drugSpec").val(dosePerUnit + doseUnits);
    }
    function changeDoseUnits() {
        var dosePerUnit = document.getElementById("dosePerUnit").value;
        var doseUnits = document.getElementById("doseUnits").value;
        $("#drugSpec").val(dosePerUnit + doseUnits);
    }
</script>